import { CoolController, BaseController } from '@cool-midway/core';
import { DemandInfoEntity } from '../../entity/info';
import { Body, Get, Inject, Post, Query } from '@midwayjs/core';
import { DemandInfoService } from '../../service/info';

/**
 * 需求信息
 */
@CoolController({
  api: ['add', 'delete', 'update', 'info', 'list', 'page'],
  entity: DemandInfoEntity,
})
export class AppDemanInfoController extends BaseController {
  /**
   * 其他接口
   */
  @Inject()
  ctx;

  @Inject()
  userInfoService: DemandInfoService;

  @Post('/addDemand')
  async addDemand(@Body() body) {
    return this.ok(await this.userInfoService.addDemand(body));
  }

  @Post('/updateDemand')
  async updateDemand(@Body() body) {
    return this.ok(await this.userInfoService.updateDemand(body));
  }

  @Get('/getDemandByUserId')
  async getDemandByUserId() {
    return this.ok(
      await this.userInfoService.getDemandByUserId(this.ctx.user.unionid)
    );
  }

  @Get('/getDemandById')
  async getDemandById(@Query('uuid') key: string) {
    return this.ok(await this.userInfoService.getDemandById(key));
  }
}
